#ifndef BATCH_H
#define BATCH_H

#include <QAbstractListModel>
#include <QObject>

class Batch : public QAbstractListModel
{
    Q_OBJECT
public:
    Q_PROPERTY(QString batchNo READ batchNo WRITE setBatchNo  NOTIFY signalBatchNoChanged)
public:
    explicit Batch(QObject *parent = nullptr);
    Q_INVOKABLE bool addBatch(QString product, QString workShop);
    Q_INVOKABLE bool updateBatch(QString desc);
    Q_INVOKABLE QVariantMap get(int row) const;

public:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

signals:
    void signalBatchNoChanged();
public:
    QString batchNo();
    void setBatchNo(QString batchNo);

private:
    bool loadBatch(const QString& filter);

private:
    QString m_batchNo;
    QString m_product;
    QString m_workShop;
    QHash<int, QByteArray> m_roles;
    QList<QHash<QString,QVariant>> m_records;
};

#endif // BATCH_H
